package com.lanyou.esb.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;
import com.lanyou.cook.datadictionary.KettleJobScheduleStatus;
import com.lanyou.cook.datadictionary.ScheduleRunResult;
import com.lanyou.cook.entity.domain.FieldSystem;
import com.lanyou.cook.service.DataDictionaryService;
import com.lanyou.esb.datadictionary.ForwardStatus;


@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = "T_ESB_BU_STORE_FORWARD")
public class StoreForward{
	
	private String id;
	
	private FieldSystem system;
	
	private Http http;
	
	private Date forwardDate;
	
	private int forwardTimes;
	
	private String forwardState;
	
	private String isEnable;

	private String creator;

	private String modifier;

	private Date createTime;

	private Date modifyTime;
	
	
	private String  field;
	private String  fieldId;
	
	private String  systemName;
	private String  systemId;
	
	private String interfaceName;
	
	@Transient
	public String getFieldId() {
		return fieldId;
	}

	public void setFieldId(String fieldId) {
		this.fieldId = fieldId;
	}
	
	@Transient
	public String getSystemId() {
		return systemId;
	}

	public void setSystemId(String systemId) {
		this.systemId = systemId;
	}
	
	@Column(name="IF_NAME")
	public String getInterfaceName() {
		return interfaceName;
	}

	public void setInterfaceName(String interfaceName) {
		this.interfaceName = interfaceName;
	}

	private int totalTime;
	
	@Transient
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}
	
	@Transient
	public String getSystemName() {
		return systemName;
	}

	public void setSystemName(String systemName) {
		this.systemName = systemName;
	}
	
	@Transient
	public int getTotalTime() {
		return totalTime;
	}

	public void setTotalTime(int totalTime) {
		this.totalTime = totalTime;
	}

	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = "FORWARD_ID", length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "FIELD_SYSTEM_ID")
	public FieldSystem getSystem() {
		return system;
	}

	public void setSystem(FieldSystem system) {
		this.system = system;
	}
	
	@ManyToOne
	@JoinColumn(name = "IF_ID")
	public Http getHttp() {
		return http;
	}

	public void setHttp(Http http) {
		this.http = http;
	}

	
	@Column(name = "FORWARD_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getForwardDate() {
		return forwardDate;
	}

	public void setForwardDate(Date forwardDate) {
		this.forwardDate = forwardDate;
	}
	
	@Column(name = "FORWARD_TIMES")
	public int getForwardTimes() {
		return forwardTimes;
	}

	public void setForwardTimes(int forwardTimes) {
		this.forwardTimes = forwardTimes;
	}
	
	@Column(name = "FORWARD_STATUS", length = 2)
	public String getForwardState() {
		return forwardState;
	}

	public void setForwardState(String forwardState) {
		this.forwardState = forwardState;
	}

	@Column(name = "IS_ENABLE", length = 2)
	public String getIsEnable() {
		return isEnable;
	}

	public void setIsEnable(String isEnable) {
		this.isEnable = isEnable;
	}

	@CreatedBy
	@Column(length = 50, updatable = false)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@LastModifiedBy
	@Column(length = 50)
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "CREATED_DATE", updatable = false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
	@Transient
	public String getFieldSystemName() {
		try {
			return (String) PropertyUtils.getProperty(system, "name");
		} catch (Exception e) {
			return null;
		}
	}
	
	@Transient
	public String getFieldName() {
		try {
			return (String) PropertyUtils.getProperty(system, "field.name");
		} catch (Exception e) {
			return null;
		}
	}
	
	@Transient
	public String getIfName() {
		try {
			return (String) PropertyUtils.getProperty(http, "interfaceName");
		} catch (Exception e) {
			return null;
		}
	}
	
	@Transient
	public String getStatusForDisplay() {
		return DataDictionaryService.getInstance().getValueName(ForwardStatus.TypeCode,forwardState);
	}
	

	
	
}